from typing import Optional
from peewee import Value
from pydantic import BaseModel

class ItemBase(BaseModel):
    id:Optional[int]
    url:str
    state:int
    class Config:
        orm_mode=True

class PageModel(ItemBase):
    order:int
    pass

class ChapterModel(ItemBase):
    order:int
    title:str
    page_count:int
    pages:list[PageModel]

class BookModel(ItemBase):
    title:str
    chapter_count:int
    cover_url:str
    state:int
    progress:float

class ProgressModel(BaseModel):
    book_id:int
    value:float

    @staticmethod
    def empty_progress():
        return ProgressModel(book_id=-1,value=0)
    
    @staticmethod
    def random_progress():
        import random
        return ProgressModel(book_id=random.randint(0,7),value=random.random())


